package com.ktgj.service.controller;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ktgj.common.core.domain.R;
import com.ktgj.common.log.annotation.SignatureValidation;
import com.ktgj.customer.api.RemoteCustomerService;
import com.ktgj.customer.api.domain.Coupon;
import com.ktgj.customer.api.domain.Customer;
import com.ktgj.flight.api.RemoteFlightService;
import com.ktgj.flight.api.domain.AirportTerminalApi;
import com.ktgj.flight.api.domain.AirportTerminalDTO;
import com.ktgj.service.common.JTu.JTdomain.QRCodesNewModel;
import com.ktgj.service.common.JTu.JingTu;
import com.ktgj.service.domain.*;
import com.ktgj.service.domain.vo.*;
import com.ktgj.service.service.IViphallService;
import javafx.geometry.Pos;
import jdk.nashorn.internal.runtime.RewriteException;
import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.support.SimpleTriggerContext;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.service.service.IOrderViphallService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;
import sun.java2d.pipe.ValidatePipe;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * 贵宾厅订单Controller
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@ControllerAdvice
@RestController
@RequestMapping("/orderviphalls")
public class OrderViphallController extends BaseController
{
    @Autowired
    private IOrderViphallService orderViphallService;

    @Autowired
    private RemoteCustomerService remoteCustomerService;

    /**
     * 查询贵宾厅订单列表
     */
    //@PreAuthorize(hasPermi = "service:viphall:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderViphall orderViphall)
    {
        startPage();
        List<OrderViphall> list = orderViphallService.selectOrderViphallList(orderViphall);
        return getDataTable(list);
    }

    /**
     * 导出贵宾厅订单列表
     */
    //@PreAuthorize(hasPermi = "service:viphall:export")
    @Log(title = "贵宾厅订单 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderViphall orderViphall) throws IOException
    {
        List<OrderViphall> list = orderViphallService.selectOrderViphallList(orderViphall);
        ExcelUtil<OrderViphall> util = new ExcelUtil<OrderViphall>(OrderViphall.class);
        util.exportExcel(response, list, "贵宾厅订单 数据");
    }

    /**
     * 获取贵宾厅订单详细信息
     */
    //@PreAuthorize(hasPermi = "service:viphall:query")
    @GetMapping(value = "/{orderviphallId}")
    public AjaxResult getInfo(@PathVariable("orderviphallId") Long orderviphallId)
    {
        return AjaxResult.success(orderViphallService.selectOrderViphallById(orderviphallId));
    }

    /**
     * 新增贵宾厅订单
     */
    //@PreAuthorize(hasPermi = "service:viphall:add")
    @Log(title = "贵宾厅订单 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderViphall orderViphall)
    {
        return toAjax(orderViphallService.insertOrderViphall(orderViphall));
    }

    /**
     * 修改贵宾厅订单
     */
    //@PreAuthorize(hasPermi = "service:viphall:edit")
    @Log(title = "贵宾厅订单 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderViphall orderViphall)
    {
        return toAjax(orderViphallService.updateOrderViphall(orderViphall));
    }

    /**
     * 删除贵宾厅订单
     */
    //@PreAuthorize(hasPermi = "service:viphall:remove")
    @Log(title = "贵宾厅订单 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderviphallIds}")
    public AjaxResult remove(@PathVariable Long[] orderviphallIds)
    {
        return toAjax(orderViphallService.deleteOrderViphallByIds(orderviphallIds));
    }

    /**
     * 贵宾厅订单--填写订单
     * @param servletRequest
     * @param map
     * @return
     */
    @PostMapping("/queryHallOrderInfo")
    public AjaxResult queryHallOrderInfo(HttpServletRequest servletRequest, @RequestBody(required = false) Map<String, Object> map) {
        String token = servletRequest.getHeader("token");
        if (map.get("viphallId") != null && !map.get("viphallId").equals("")){
            Long viphallId = Long.valueOf(map.get("viphallId").toString());
            FillOrderResponse response = null;
            try {
                response = orderViphallService.queryHallOrderInfo(token, viphallId);
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.error(e.getMessage());
            }
            return AjaxResult.success(response);
        }
        else {
            return AjaxResult.error("缺少必要参数");
        }
    }

    /**
     * 生成贵宾厅订单
     * @param request
     * @param map
     * @return
     */
//    @SignatureValidation
    @PostMapping("/saveOrderVipHall")
    public AjaxResult saveOrderViphall(HttpServletRequest request, @RequestBody(required = false) Map<String, Object> map) {
        String token = request.getHeader("token");
        Long viphallId = Long.valueOf(map.get("viphallId").toString());
        String arrivalDate = String.valueOf(map.get("arrivalDate"));
        Long peopleNumber = Long.valueOf(map.get("peopleNumber").toString());
        BigDecimal payment = new BigDecimal(map.get("payment").toString());
        BigDecimal points = new BigDecimal(map.get("points").toString());
        Long couponId = null;
        if (map.get("couponId") != null &&!map.get("couponId").equals("")){
            couponId = Long.valueOf(map.get("couponId").toString());
        }
        BigDecimal totalsalePrice = new BigDecimal(map.get("totalsalePrice").toString());
        BigDecimal usedDeposit = new BigDecimal(map.get("usedDeposit").toString());
        Long employeeId = 1L;
        String contactName = String.valueOf(map.get("contactName"));
        String contactPhone = String.valueOf(map.get("contactPhone"));
        String usePoint = map.get("usePoint").toString();
        String useDeposits = map.get("useDeposits").toString();
        String orderId;
        try {
            orderId = orderViphallService.saveOrder(token, viphallId, arrivalDate, peopleNumber, payment, points, couponId, totalsalePrice, usedDeposit, employeeId, contactName, contactPhone, usePoint, useDeposits);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(orderId);
    }

    /**
     * 贵宾厅订单收银台
     * @param request
     * @return
     */
    @PostMapping("/queryPayOrder")
    public AjaxResult queryPayOrder(HttpServletRequest request, @RequestBody Map<String, Object> map) {
        String token = request.getHeader("token");
        Long orderNumber = Long.valueOf(map.get("orderNumber").toString());
        String businessType = String.valueOf(map.get("businessType"));
        R<Customer> customer;
        try {
            customer = remoteCustomerService.getLoginCustomerByToken(token);
            return AjaxResult.success(orderViphallService.queryByPayOrder(customer.getData().getCustomerId(), orderNumber, businessType));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.expired("登录已过期，请重新登录");
        }
    }

    /**
     * 订单核销
     * @param personNum
     * @param orderviphallId
     * @return
     */
    @GetMapping("/descOrder/{personNum}/{orderviphallId}")
    public AjaxResult descOrder(@PathVariable int personNum, @PathVariable Long orderviphallId) {
        int hall = orderViphallService.descOrderVipHall(personNum, orderviphallId);
        return AjaxResult.success(hall);
    }

    /**
     * 贵宾厅订单支付成功页面展示
     * @param maps
     * @return
     */
    @PostMapping("/selectOrderViphallNumber")
    public AjaxResult selectOrderViphallNumber(@RequestBody Map<String, Object> maps) {
        Long orderviphallId = Long.valueOf(maps.get("orderviphallId").toString());
        OrderViphall orderViphall = orderViphallService.selectOrderViphallNumber(orderviphallId);
        Map<String, Object> map = new HashMap<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createTime = format.format(orderViphall.getCreateTime());
        map.put("orderNumber", orderViphall.getOrderNumber());
        map.put("createTime", createTime);
        map.put("memberAccountpaymentmethod", orderViphall.getMemberAccountpaymentmethod());
        return AjaxResult.success().put("data", map);
    }

    /**
     * 首页-黄金会员-进行中/已使用
     * @param request
     * @return
     */
    @PostMapping("/selectOrderViphallByStatus")
    public AjaxResult selectOrderViphallByStatus(HttpServletRequest request) {
        String token = request.getHeader("token");
        R<Customer> customer = remoteCustomerService.getLoginCustomerByToken(token);
        Long customerId = customer.getData().getCustomerId();
        List<OrderConductOrUse> list = orderViphallService.selectOrderViphallByStatus(customerId);
        return AjaxResult.success().put("data", list);
    }

    /**
     * 贵宾厅订单二维码
     * @param request
     * @param maps
     * @return
     */
    @PostMapping("/orderViphallQRCode")
    public AjaxResult orderViphallQRCode(HttpServletRequest request, @RequestBody Map<String, Object> maps) {
        String token = request.getHeader("token");
        R<Customer> customer = remoteCustomerService.getLoginCustomerByToken(token);
        Long customerId = customer.getData().getCustomerId();
        Long orderviphallId = Long.valueOf(maps.get("orderviphallId").toString());
        Map<String, Object> map;
        try {
            map = orderViphallService.orderViphallQRCode(customerId, orderviphallId);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        return AjaxResult.success().put("data", map);
    }

    /**
     * 贵宾厅订单二维码解码
     * @param map
     * @return
     */
    @PostMapping("/QRCodeDecryption")
    public AjaxResult QRCodeDecryption(@RequestBody Map<String, Object> map) {
        String decryption = String.valueOf(map.get("decryption"));
        return AjaxResult.success(orderViphallService.QRCodeDecryption(decryption));
    }

    /**
     * BASE64加密
     */
    private static final String UTF_8 = "UTF-8";

    public static String encodeData(String inputData) {
        try {
            return new String(Base64.encodeBase64(inputData.getBytes(UTF_8)), UTF_8);
        }catch (Exception e){
            return null;
        }

    }

    /**
     * 贵宾厅订单详情
     * */
    @PostMapping("/selectVIPRoomOrderDetails")
    public AjaxResult selectVIPRoomOrderDetails(HttpServletRequest request, @RequestBody Map<String, Object> maps) {
        Long orderviphallId = Long.valueOf(String.valueOf(maps.get("orderviphallId")));
        String token = request.getHeader("token");
        R<Customer> customer = remoteCustomerService.getLoginCustomerByToken(token);
        Long customerId = customer.getData().getCustomerId();
        List<OrderViphall> orderViphallList=orderViphallService.selectOrderViphallByCustomerId(customerId, orderviphallId);
        List<Map<String, Object>> mapList = new ArrayList<>();
        List<OrderViphallVo> orderViphallVoList=new ArrayList<>();

        for (OrderViphall viphall : orderViphallList) {
            if (viphall.getIsDeleted().equals("false")){
                Map<String, Object> map = new HashMap<>();
                map.put("status", viphall.getStatus());
                for (Viphall viphalls : viphall.getViphalls()){
                    map.put("viphallName", viphalls.getViphallName());
                    map.put("customerServiceTel", viphalls.getCustomerServiceTel());
                    map.put("address", viphalls.getAddress());
                }
                map.put("totalsalePrice", viphall.getTotalsalePrice());
                map.put("peopleNumber", viphall.getPeopleNumber());
                map.put("arrivalviphallTime", viphall.getArrivalviphallTime());
                map.put("remark", viphall.getRemark());
                map.put("createTime", new Date());
                map.put("contractViphallId", viphall.getContractViphallId());
                map.put("twoKtserviceensionalCode", viphall.getTwoKtserviceensionalCode());
                map.put("orderviphallId", viphall.getOrderviphallId());
                map.put("contactPhone", viphall.getContactPhone());
                map.put("paymentMoney", viphall.getPaymentMoney());
//                map.put("rightdetalName", viphall.getRightdetail().getRightdetalName());
//                map.put("rightdetailDescribe", viphall.getCardRightdetail().getRightdetailDescribe());
                mapList.add(map);

                OrderViphallVo orderViphallVo = new OrderViphallVo();
                orderViphallVo.setStatus(viphall.getStatus());
                for (Viphall viphalls : viphall.getViphalls()){
                    orderViphallVo.setViphallName(viphalls.getViphallName());
                    orderViphallVo.setCustomerServiceTel(viphalls.getCustomerServiceTel());
                    orderViphallVo.setAddress(viphalls.getAddress());
                }
                orderViphallVo.setTotalsalePrice(viphall.getTotalsalePrice());
                orderViphallVo.setPeopleNumber(viphall.getPeopleNumber());
                orderViphallVo.setArrivalviphallTime(viphall.getArrivalviphallTime());
                orderViphallVo.setRemark(viphall.getRemark());
                orderViphallVo.setCreateTime(new Date());
                orderViphallVo.setOrderviphallId(viphall.getOrderviphallId());
                orderViphallVo.setContactPhone(viphall.getContactPhone());
                orderViphallVo.setPaymentMoney(viphall.getPaymentMoney());
//                orderViphallVo.setRightdetalName(viphall.getRightdetail().getRightdetalName());
//                orderViphallVo.setRightdetailDescribe(viphall.getCardRightdetail().getRightdetailDescribe());
                orderViphallVoList.add(orderViphallVo);
            }
        }

        String base64 = encodeData(mapList.toString());

        return AjaxResult.success(orderViphallVoList).put("twoKtserviceensionalCode", base64);
    }

    /**
     * 贵宾厅订单二维码解密
     * @param map
     * @return
     */
    //TODO 接口文档未写
    @PostMapping("/OrderViphallByCustomerId")
    public AjaxResult OrderViphallByCustomerId(@RequestBody Map<String, Object> map) {
        String twoKtserviceensionalCode = String.valueOf(map.get("twoKtserviceensionalCode"));
        return AjaxResult.success(orderViphallService.QRCodeDecryption(twoKtserviceensionalCode));
    }

    /**
     * 删除订单
     * */
    @PostMapping("/deleteVipRoomOrder")
    public AjaxResult deleteVipRoomOrder(@RequestBody Map<String, Object> map){
        Long orderviphallId = Long.valueOf(map.get("orderviphallId").toString());
        return toAjax(orderViphallService.updateOrderViphallByIsDeleted(orderviphallId));
    }

    /**
     * 取消订单-立即支付（修改状态）-申请退款
     * */
    @PostMapping("/ModifyStatusVipRoomOrder")
    public AjaxResult ModifyStatusVipRoomOrder(HttpServletRequest request, @RequestBody Map<String, Object> map){
        Long orderviphallId = Long.valueOf(String.valueOf(map.get("orderviphallId")));
        String type = map.get("type").toString();
        String token = request.getHeader("token");
        R<Customer> customer = remoteCustomerService.getLoginCustomerByToken(token);
        Long customerId = customer.getData().getCustomerId();
        return toAjax(orderViphallService.updateOrderViphallByPaymentStatus(customerId, orderviphallId, type));
    }

    /**
     * 修改订单
     */
    @PostMapping("/updateVipRoomOrder")
    public AjaxResult updateVipRoomOrder(@RequestBody Map<String, Object> map){
        String contactName = map.get("contactName").toString();
        String contactPhone = map.get("contactPhone").toString();
        Long orderviphallId = Long.valueOf(String.valueOf(map.get("orderviphallId")));

        OrderViphall orderViphall = new OrderViphall();
        orderViphall.setOrderviphallId(orderviphallId);
        orderViphall.setContactName(contactName);
        orderViphall.setContactPhone(contactPhone);

        return toAjax(orderViphallService.updateOrderViphallByContactPhone(orderViphall));
    }

    /**
     * 查看行程用
     * @param orderviphallId
     * @return
     */
    @PostMapping("/queryViphallTrip")
    public Map<String, Object> queryViphallTrip(@RequestParam("orderviphallId") Long orderviphallId) {
        Map<String, Object> viphallTrip = orderViphallService.queryViphallTrip(orderviphallId);
        return viphallTrip;
    }

    /**
     * 定制行程-单程
     * @param customerId
     * @return
     */
    @PostMapping("/queryItineraryHall")
    public AjaxResult queryItineraryHall(@RequestParam("customerId") Long customerId) {
        OrderViphall viphall = orderViphallService.queryItinerary(customerId);
        if (!StringUtils.isEmpty(viphall))
            return AjaxResult.success(viphall);
        else
            return AjaxResult.error("无可定制行程的订单！");
    }

    @PostMapping("/selectItineraryHall")
    public Map<String, Object> selectItineraryHall(@RequestParam("orderviphallId") Long orderviphallId) {
        Map<String, Object> itinerary = orderViphallService.selectItinerary(orderviphallId);
        return itinerary;
    }

    /**
     * 微信小程序支付
     * @param map
     * @return
     */
    @PostMapping("/wechatPay")
    public AjaxResult wechatPay(@RequestBody Map<String, Object> map) {
        String openId = String.valueOf(map.get("openId"));
        Long orderNumber = Long.valueOf(map.get("orderNumber").toString());

        BigDecimal amount = new BigDecimal(0);
        if (map.get("amount") != null && !map.get("amount").equals("")){
            amount = new BigDecimal(map.get("amount").toString());
        }
        String type = map.get("type").toString();

        Map<String, Object> wechatPay;
        try {
            wechatPay = orderViphallService.wechatPay(openId, orderNumber, amount, type);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        if (wechatPay != null)
            return AjaxResult.success(wechatPay);
        else
            return AjaxResult.error("支付失败");
    }

    /**
     * 查询会员贵宾厅订单列表
     * */
    @PostMapping("/selectOrderViphallByCustomer")
    public AjaxResult selectOrderViphallByCustomer(HttpServletRequest request, @RequestBody Map<String, Object> map){
        String type = null;
        if (map.get("type") != null && !map.get("type").equals("")){
            type = map.get("type").toString();
        }
        String token = request.getHeader("token");
        R<Customer> customer = remoteCustomerService.getLoginCustomerByToken(token);
        Long customerId = customer.getData().getCustomerId();

        List<OrderViphall> orderViphallList;
        try {
            orderViphallList = orderViphallService.selectOrderViphallByCustomer(customerId, type);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        if (orderViphallList != null && orderViphallList.size() > 0){
            return AjaxResult.success(orderViphallList);
        }
        else {
            return AjaxResult.error("没有数据");
        }
    }

    /**
     * 查询会员贵宾厅订单列表(远)
     * */
    @PostMapping("/orderViphallByCustomer")
    public List<OrderViphall> orderViphallByCustomer(@RequestBody Map<String, Object> map){
        Long customerId = Long.valueOf(map.get("customerId").toString());
        String type = null;
        List<OrderViphall> orderViphallList;
        try {
            orderViphallList = orderViphallService.selectOrderViphallByCustomer(customerId, type);
        } catch (Exception e){
            return null;
        }

        if (orderViphallList != null && orderViphallList.size() > 0){
            return orderViphallList;
        }
        else {
            return null;
        }
    }

    /**
     * 获取用户贵宾厅订单数量
     */
    @PostMapping("/queryVipHallOrderNumber")
    public int queryVipHallOrderNumber(@RequestBody Long customerId) {
        return orderViphallService.queryVipHallOrderNumber(customerId);
    }

    /**
     * 贵宾厅订单列表
     * */
    @PostMapping("/selectVipHallOrederList")
    public TableDataInfo selectVipchannelOrederList(@RequestBody VipchannelOrederParameterVo vipchannelOrederParameterVo){
        startPage();
        List<OrderViphall> vipchannelOrederTotalVo = orderViphallService.selectVipchannelOrederListVo(vipchannelOrederParameterVo);
        return getDataTable(vipchannelOrederTotalVo);
    }

    /**
     * 贵宾厅订单列表
     * */
    @PostMapping("/VipHallOrederList")
    public List<OrderViphall> VipchannelOrederList(@RequestBody VipchannelOrederParameterVo vipchannelOrederParameterVo){
        List<OrderViphall> vipchannelOrederTotalVo = orderViphallService.selectVipchannelOrederListVo(vipchannelOrederParameterVo);
        return vipchannelOrederTotalVo;
    }

    /**
     * 贵宾厅订单详细+orderNumber
     * */
    @PostMapping("/selectVipHallDetailsByorderNumber")
    public AjaxResult selectVipHallDetailsByorderNumber(@RequestBody Map<String, Object> map){
        if (map.get("orderNumber") != null && !map.get("orderNumber").equals("")){
            Long orderNumber = Long.valueOf(map.get("orderNumber").toString());
            OrderViphallDetailsVo orderViphallDetailsVo;
            try {
                orderViphallDetailsVo = orderViphallService.selectVipHallDetailsByorderNumber(orderNumber);
            } catch (Exception e){
                return AjaxResult.error(e.getMessage());
            }
            if (orderViphallDetailsVo != null){
                return AjaxResult.success(orderViphallDetailsVo);
            }
            else {
                return AjaxResult.error("未查到数据");
            }
        }
        else {
            return AjaxResult.error("缺少必要参数");
        }
    }
    /**
     * 贵宾厅订单详细
     * */
    @PostMapping("/selectVipHallDetails")
    public AjaxResult selectVipHallDetails(@RequestBody Map<String, Object> map){
        Long orderId = null;
        String orderNum = null;
        if (map.get("orderId") != null && !map.get("orderId").equals("")){
            orderId = Long.valueOf(map.get("orderId").toString());
        }
        else if (map.get("orderNum") != null && !map.get("orderNum").equals("")){
            orderNum = map.get("orderNum").toString();
        }
        else {
            return AjaxResult.error("缺少必要参数");
        }

        OrderViphallDetailsVo orderViphallDetailsVo;
        try {
            orderViphallDetailsVo = orderViphallService.selectVipHallDetails(orderId, orderNum);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
        if (orderViphallDetailsVo != null){
            return AjaxResult.success(orderViphallDetailsVo);
        }
        else {
            return AjaxResult.error("未查到数据");
        }
    }

    /**
     * 行程贵宾厅订单
     * */
    @PostMapping("/journeyOrderViphallVo")
    public JourneyOrderViphallVo journeyOrderViphallVo(@RequestBody Map<String, Object> map) {
        Long orderviphallId = Long.valueOf(map.get("orderviphallId").toString());
        JourneyOrderViphallVo journeyOrderViphallVo = orderViphallService.journeyOrderViphallVo(orderviphallId);
        return journeyOrderViphallVo;
    }

    /**
     * 贵宾厅退单
     * */
    @PostMapping("/chargebackOrderViphall")
    public AjaxResult chargebackOrderViphall(@RequestBody Map<String, Object> map){
        if (map.get("orderviphallId") != null && !map.get("orderviphallId").equals("")){
            Long orderviphallId = Long.valueOf(map.get("orderviphallId").toString());
            int i = orderViphallService.chargebackOrderViphall(orderviphallId);
            if (i > 0){
                return AjaxResult.success("退单成功");
            }
            else {
                return AjaxResult.error("退单失败");
            }
        }
        else {
            return AjaxResult.error("缺少必要参数");
        }
    }

    /**
     * 订单号获取贵宾厅订单信息
     * */
    @PostMapping("/orderNum")
    public OrderViphall orderNum(@RequestBody Map<String, Object> map){
        String orderNum = map.get("orderNum").toString();
        OrderViphall orderViphall = orderViphallService.orderNum(orderNum);
        return orderViphall;
    }

    /**
     * 员工所属部门贵宾厅列表
     * */
    @PostMapping("/deptVipHallOrderList")
    public TableDataInfo deptVipHallOrderList(@RequestBody Map<String, Object> map){
        startPage();
        Long id = Long.valueOf(map.get("id").toString());
        List<OrderViphall> orderViphallList;
        try {
            orderViphallList = orderViphallService.deptVipHallOrderList(id);
        } catch (Exception e){
            return null;
        }

        return getDataTable(orderViphallList);
    }

    //创建贵宾厅二维码数据
    @PostMapping("/createQRCode")
    public AjaxResult createOrderQRCode(HttpServletRequest request,@RequestBody OrderQRCodeVo orderQRCodeVo) {
        String token = request.getHeader("token");
        R<Customer> customer = remoteCustomerService.getLoginCustomerByToken(token);
        if (customer == null) {
            return AjaxResult.error("会员信息为空");
        }
        orderQRCodeVo.customerId = customer.getData().getCustomerId();
        String qrCodeInfo = orderViphallService.getVipHallOrderQRCode(orderQRCodeVo);
        return AjaxResult.success(qrCodeInfo);
    }

    //核销贵宾厅订单数据
    @PostMapping("/checkQRCode")
    public AjaxResult checkQRcode(@RequestBody Map<String, String> map) {
        String qrCode = map.get("qrCode");
        String userCount = map.get("userCount");
        String deptId = map.get("deptId");
        return orderViphallService.checkViphallOrderORCode(qrCode, userCount, deptId);
    }
}
